﻿using System;
using System.Collections.Generic;
using System.Text;

namespace XAJH
{
    /// <summary>
    /// 怪物类
    /// </summary>
    public class Monster
    {
        #region 属性

        /// <summary>
        /// 起始点x坐标
        /// </summary>
        private int hp_X_Start = 0;
        /// <summary>
        /// 获取或设置血条开始X坐标
        /// </summary>
        public int Hp_X_Start
        {
            get { return hp_X_Start; }
            set { hp_X_Start = value; }
        }

        private int hp_X_End = 800;
        /// <summary>
        /// 获取或设置血条结束X坐标
        /// </summary>
        public int Hp_X_End
        {
            get { return hp_X_End; }
            set { hp_X_End = value; }
        }

        private int hp_Y = 82;
        /// <summary>
        /// 获取或设置血条Y坐标
        /// </summary>
        public int Hp_Y
        {
            get { return hp_Y; }
            set { hp_Y = value; }
        }

        private IntPtr handle;
        /// <summary>
        /// 获取或设置窗口句柄
        /// </summary>
        public IntPtr Handle
        {
            get { return handle; }
            set { handle = value; }
        }

        #endregion

        #region 初始化

        /// <summary>
        /// 
        /// </summary>
        /// <param name="hWnd"></param>
        public Monster(IntPtr hWnd)
        {
            this.Handle = hWnd;
            //  获取窗口矩形
            var rect = FormHelper.GetWindowRect(hWnd);
            //  根据窗口大小计算位置
            if (rect.Width == 1024 && rect.Height == 768)
            {
                #region 血条位置

                this.Hp_X_Start = 0;
                this.Hp_X_End = 100;
                this.Hp_Y = 82;

                #endregion
            }
        }

        #endregion

        /// <summary>
        /// 获取当前怪物是否满血
        /// </summary>
        /// <returns></returns>
        public bool IsHpFull
        {
            get
            {
                //  获取起始点颜色是否为红色
                bool full1 = GraphicsHelper.GetColor(this.Handle, this.Hp_X_Start, this.Hp_Y).R >= 200;
                //  定义中间是否为红色
                bool full2 = true;
                //  从起始点递增，直至结束点，判断RGB红色
                for (int i = this.Hp_X_Start; i <= this.Hp_X_End; i++)
                {
                    //  获取RGB红色
                    var color = GraphicsHelper.GetColor(this.Handle, i, this.Hp_Y);
                    if (color.R < 200)
                    {
                        full2 = false;
                        break;
                    }
                }
                //  获取结束点颜色是否为红色
                bool full3 = GraphicsHelper.GetColor(this.Handle, this.Hp_X_End, this.Hp_Y).R >= 200;
                //  如果三个条件都满足，则为满血状态
                return full1 && full2 && full3;
            }
        }

        /// <summary>
        /// 获取是否空血
        /// </summary>
        public bool IsHpEmpty
        {
            get
            {
                //  获取起始点颜色是否为红色
                bool empty1 = GraphicsHelper.GetColor(this.Handle, this.Hp_X_Start, this.Hp_Y).R < 200;
                //  定义中间是否为红色
                bool empty2 = true;
                //  从起始点递增，直至结束点，判断RGB红色
                for (int i = this.Hp_X_Start; i <= this.Hp_X_End; i++)
                {
                    //  获取RGB红色
                    var color = GraphicsHelper.GetColor(this.Handle, i, this.Hp_Y);
                    if (color.R >= 200)
                    {
                        empty2 = false;
                        break;
                    }
                }
                //  获取结束点颜色是否为红色
                bool empty3 = GraphicsHelper.GetColor(this.Handle, this.Hp_X_End, this.Hp_Y).R < 200;
                //  如果三个条件都满足，则为空血状态
                return empty1 && empty2 && empty3;
            }
        }




    }
}
